
package mballs;

// Precision timer class.
public class PTimer {
    
    // Class member variables.
    private long cTime;
    private long difTime;
    private long oldTime;
    
    // Class constructor.
    public PTimer() {
        cTime = System.nanoTime() / 1000000;
        difTime = 0;
        oldTime = cTime;
    }
    
    // Update the timer. (call each frame)
    public long update() {
        cTime = System.nanoTime() / 1000000;
        difTime = cTime - oldTime;
        oldTime = cTime;
        return difTime;
    }
    
    // Reset the timer. (if you haven't been updating)
    public void reset() {
        cTime = System.nanoTime() / 1000000;
        difTime = 0;
        oldTime = cTime;
    }
}
